package cn.xf.service.impl;

import cn.xf.dao.IProductDao;
import cn.xf.domain.Product;
import cn.xf.service.IProductService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xiaofu
 * @date 2021-05-11 12:31
 * @email dearaf@163.com
 */
@Service
@Transactional
public class ProductServiceImpl implements IProductService {

    @Autowired
    private IProductDao productDao;

    @Override
    public List<Product> findAll() {
        return productDao.findAll();
    }

    @Override
    public void save(Product product) {
        productDao.save(product);
    }

    @Override
    public void deleByIds(List<String> idList) {
        for (String id :idList) {
            productDao.deleById(id);
        }

    }

    @Override
    public void changeStatusByIds(List<String> idList, String status) {
        for (String id :idList) {
            productDao.changeStatusByIds(id,status);
        }
    }

    @Override
    public Product selectById(String id) {
        return productDao.selectById(id);
    }

    @Override
    public void updateById(Product product) {
        productDao.updateById(product);
    }

    @Override
    public List<Product> findAllByPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        return productDao.findAll();
    }
}
